Jump to content

Disable Function Until Page Loads


METOOTECH

Recommended Posts

Hi all, my other post got no response, so maybe we can solve my problem one step at a time. What I would like to do here is disable a function (a popup) in a head statement script while my page is loading, and enable the function once my page has loaded. Would I need to do this in a separate script? If so, where would the script be placed... in the head area before or after the script containing the function, or in the body before or after the onclicks that trigger the function? Any help with this would be much appreciated.thanks... Metootech

Link to comment
Share on other sites

Well, popup blockers aren't written in Javascript. They don't disable a function, they intercept the call to open the window and decide if they really want to do that or not. You can see if you can save a function, if you can then you should be able to redefine the function to do nothing until the page finishes loading, and then copy the function back. See if something like this works:

alert("defining function");  function test_func()  {	alert("this is the test function");  }  alert("calling the function");  //calling the function..  test_func();  alert("saving the function");  //try to save it  temp = test_func;  alert("redefining the function");  //redefine  test_func = function() { alert("this is the new function"); }  alert("calling the new function");  //call it again  test_func();  alert("calling the old function");  //try the saved version  temp();  alert("copy the function back");  //try to copy it back  test_func = temp;    alert("call the original function");  //test it again  test_func();

It looks like it works in Opera, you might be able to use something like that.

Link to comment
Share on other sites

Thanks for the replies! I've tried the defer and it doesn't work on this application. I guess you're right about the "disable function"... What I'm trying to do is "stop a script from working while my page loads" The script is a popup larger view of an image. If you click on a thumbnail, you get the larger view as a popup. The problem is... if you click on a thumbnail before all the images on the page are loaded, the popup stops the rest of the images from loading (also stops animated gifs from working) and when the popup is closed the page does not resume loading the rest of the images. You must refresh the page in order to load the rest of the images. Although I can put an automatic refresh of the parent page on the popup page that works when the popup closes, this becomes irritating to have the parent page refresh after every popup once the parent page has fully loaded. Here's a link to one of my pages... see for yourself... thanksCutzit Cutlery Tactical Knives

Link to comment
Share on other sites

  • 2 weeks later...

couldn't you have an if statement through the functionsomething along the lines of this

var status=1;function something(){if (status==2){//code ...........}}

then when you want it enabled

status=2;

Link to comment
Share on other sites

yeah I think that would workstatus = 1function imgPopUp() { if (status == 2) { //code for this pop up here will never work until status set to 2 }}function loadStatus() { status = 2 // will only happen when the loadStatus() function is called}<body onload="java script:loadStatus()">//loadStatus function will be called immediately after the page is loaded</body>

Link to comment
Share on other sites

Not a bad idea, though I would prefer something like this instead:

var loaded = false;function doit(){	if(loaded)	{		// code goes here.	}}

<body onload="loaded=true;">

Link to comment
Share on other sites

jesh, I could not get your code to work... the image would not popup... here's the original code I'm using on the parent page... (NOTE: this post editor seperates the word java and script in the code below, it has to be one word in order for the code to work!)<head><script type="text/javascript">function PopupPic(sPicURL){window.open("image_dis2.html?"+sPicURL,"","resizable=1,HEIGHT=200,WIDTH=200,TOP=10,LEFT=100");}</script></head><body><a href='java script:PopupPic("large.jpg")'><img src="thumbnail.jpg" height="161" width="215" border=0 title='Product - Click to enlarge'></body>

Link to comment
Share on other sites

Here is the code on the popup page....the html file title is... image_dis2.html<HTML><HEAD><TITLE>Item Pop Up</TITLE><script language='javascript'>var arrTemp=self.location.href.split("?");var picUrl = (arrTemp.length>0)?arrTemp[1]:"";var NS=(navigator.appName=="Netscape")?true:false;function FitPic() {iWidth = (NS)?window.innerWidth:document.body.clientWidth;iHeight = (NS)?window.innerHeight:document.body.clientHeight;iWidth = document.images[0].width - iWidth;iHeight = document.images[0].height - iHeight;iWidth2 = iWidth + 40;iHeight2 = iHeight + 40;window.resizeBy(iWidth2,iHeight2);self.focus();}</script> </HEAD><BODY bgcolor="#cc0000" link="#ffffff" alink="#ffffff" vlink="#ffffff" onload='FitPic();' topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" onBlur="window.close()"> <div align="center"> <a href="java script:window.close();"><font size="2">Close This Window</font></a><br> <script language='javascript'>document.write("<img src='" + picUrl + "' border=0>");</script> <br> <a href="java script:window.close();"><font size="2">Close This Window</font></a></div> </BODY></HTML>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...