Communicate webGL application with html page javascript

Hi,

In web application i used the Application.ExternalCall(“MyFunction1”); function in order to communicate between the game and web-page. Actually i read the URL.

The CS code

private string fmt = "full url: {0}";

void Start (){
     Application.ExternalCall ("GetFullUrl", gameObject.name); 
}

public void SetFullUrl(string fullUrl) {
        string s = string.Format (fmt, fullUrl);
}

the JS code

function GetFullUrl(gameObjectName) {
                u.getUnity().SendMessage(gameObjectName, "SetFullUrl", window.location.href);
               
            }

Now i try to export my game as WEBGL and does not work thise code.
I found this tutorial (link), but still i could’t understand why does not working.

Any idea?

Thank you in advance

I quickly looked at your code and it should work.
Do you have any error?
Where is the JS Code?
Does your GetFullUrl method gets even called? (Put a console.log in it.)

like i notice the main problem is that in webGL doesnot exist the “var u = new UnityObject2(config);”.

the errors

An error occured running the Unity content on this page. See your browser's JavaScript console for more info. The error was:
uncaught exception: abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 268435456, (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.") at jsStackTrace@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1187:13
stackTrace@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1204:22
abort@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:3504027:44
enlargeMemory@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1223:3
Runtime.dynamicAlloc@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:368:161
_sbrk@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:14311:23
_malloc@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:3486087:16
__ZN13MemoryManager16LowLevelAllocateEj [MemoryManager::LowLevelAllocate(unsigned int)]@file:///Users/ipet/Desktop/Synthe/250515/index/Release/index.js:921397:8
__ZN17LowLevelAllocator6MallocEj [LowLevelAllocator::Malloc(unsigned int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:924430:8
__ZN21UnityDefaultAllocatorI17LowLevelAllocatorE8AllocateEji [Allocate? UnityDefaultAllocator<LowLevelAllocator?>(unsigned int, int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:922606:8
__ZN13MemoryManager8AllocateEji10MemLabelIdiPKci [MemoryManager::Allocate?1(unsigned int, int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:920755:9
__ZN13MemoryManager10ReallocateEPvji10MemLabelIdiPKci [MemoryManager::Reallocate?1(void*, unsigned int, int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:920822:9
__Z16realloc_internalPvji10MemLabelIdiPKci [realloc_internal?1(void*, unsigned int, int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:920792:8
__ZN17SharedTextureDataC2E10MemLabelIdii13TextureFormatiibb [SharedTextureData::SharedTextureData?1()]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1318354:12
__ZN9Texture2D26AllocateScaledOrPaddedDataE13TextureFormat [Texture2D::AllocateScaledOrPaddedData?1()]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1328667:2
__ZN9Texture2D25CreateScaledAndPaddedDataEPP17SharedTextureDataS2_ [Texture2D::CreateScaledAndPaddedData?2(SharedTextureData?S?**)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1328245:9
__ZN9Texture2D13UploadTextureEb [Texture2D::UploadTexture(bool)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1327634:2
__ZN9Texture2D13AwakeFromLoadE17AwakeFromLoadMode [Texture2D::AwakeFromLoad?1()]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1326543:2
__ZN18AwakeFromLoadQueue34PersistentManagerAwakeSingleObjectER6Object17AwakeFromLoadMode [AwakeFromLoadQueue::PersistentManagerAwakeSingleObject?7(Object?1?&)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1593828:2
__ZN17PersistentManager48IntegrateObjectAndUnlockIntegrationMutexInternalEi [PersistentManager::IntegrateObjectAndUnlockIntegrationMutexInternal(int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1597914:4
__ZN27TimeSliceAwakeFromLoadQueue19IntegrateTimeSlicedEi [TimeSliceAwakeFromLoadQueue::IntegrateTimeSliced(int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1494524:4
__ZN13LoadOperation19IntegrateTimeSlicedEi [LoadOperation::IntegrateTimeSliced(int)]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1494320:8
__ZN14PreloadManager26UpdatePreloadingSingleStepENS_21UpdatePreloadingFlagsE [PreloadManager::UpdatePreloadingSingleStep?N()]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1462113:9
__ZN14PreloadManager35WaitForAllAsyncOperationsToCompleteEv [PreloadManager::WaitForAllAsyncOperationsToComplete()]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1462192:3
__Z21PlayerStartFirstScenev [PlayerStartFirstScene()]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1460333:2
__Z20PlayerLoadFirstScenev [PlayerLoadFirstScene()]@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:1460353:3
_main@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:2554188:2
callMain@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:3503898:15
doRun@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:3503955:42
run/<@file:///Users/theUser/Desktop/Synthe/250515/index/Release/index.js:3503966:7

If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

Oh, yeah right! u.getUnity only works in the Web Player…

Try this instead:

function GetFullUrl(gameObjectName) {
     SendMessage(gameObjectName, "SetFullUrl", window.location.href);
}

That’s the way I do it, in one of my WebGL project.

EDIT: Essentially, only removing the u.getUnity()…

i have also try this one but again gives the above errors.

sorry now i notice that the GetfullUrl function works, but my project gives those errors.
Do i have to change the name of the topic or to create new one ?

x.

Your error seems unrelated to your problem.

It looks like you don’t have enough memory allowed for your your application. Is it big?

What is your memory size set to? (you can see in the BuildSettings/WeblGL (click on player settings), then in the inspector under Publishing Settings, there is a WebGL Memory Size field.

Posting in the WebGL section would gather more result as your problem is directly tied to that platform.

ok, i will post it there, thank you sluice.

The memory size 256.