Forum Moderators: open

Message Too Old, No Replies

Need help with JS script - detecting JS enabled, etc.

Serves different URL depending on enable or not.

         

ron_ron

3:11 am on May 7, 2004 (gmt 0)

10+ Year Member



I am not very good at JS. I have a script I am trying to modify. The script first determines whether a surfer has JS enable in their browser when they click on a link to bring them to a new page. If so, it gives them a pop-up instead of a page. If not, it gives them a target="_new" window. It works fine but I need to have it take the surfer to a different URL depending if it is the pop-up or the target="_new" window. Here is the script as is:

<script language="JavaScript" type="text/javascript">
<!--
function popup(popURL,popHeight,popWidth)
{
options="resizable,height="+popHeight+",width="+popWidth;
window.open(popURL, 'newWin', options);
}
//-->
</script>

<a href="http://www.mydomain/page1.htm" onClick="popup(this.href,480,500);return false;" target="newWin">

Click Here

</a>

In this example, the pop-up is page1.htm. If JS is not enabled, it should take them to page2.htm.

Other things I would like it to do are to allow scrolling, show status bar, and hide the URL in the status bar when someone hovers their mouse over the link for the page.

Many thanks!

Ron, JS Dummy

Bernard Marx

2:02 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The most straightforward way would be to fill the link hrefs with the URLs to 'noscript' pages, but send the pop-up function the 'script' page links:

[blue]
<a href="http://www.mydomain/page2.htm"
onClick="popup("http://www.mydomain/page1.htm",480,500);return false;"
target="_blank">[/blue]

..making sure you return false to the href, which you have.

This will result in the status message showing the incorrect URL for those script-enabled - but then you did ask about hiding the status message...

[blue]
<a href="http://www.mydomain/page2.htm"
onClick="popup("http://www.mydomain/page1.htm",480,500);return false;"
target="_blank"[/blue]
[red]onMouseOver="window.status='';return true;"[/red]
[blue]>[/blue]

For scrollbars, and status bar on the new window, we amend your popup function:

[blue]function popup(popURL,popHeight,popWidth)
{
var options="resizable,height="+popHeight+",width="+popWidth
+",scrollbars=1,status=1";
window.open(popURL, 'newWin', options);
}
[/blue]

..and you're done.

ron_ron

2:44 pm on May 7, 2004 (gmt 0)

10+ Year Member



Yes, that works very nice, thank you. Is there any way to control what is displayed in the status of the new pop-up?

ron_ron

3:07 pm on May 7, 2004 (gmt 0)

10+ Year Member



P.S.

I mean, like a message that would say something like*

Page loading, please wait .....

and then have it disappear once the page is actually loaded?

Bernard Marx

3:13 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Amend the function:


function popup(popURL,popHeight,popWidth)
{
var options="resizable,height="+popHeight+",width="+popWidth
+",scrollbars=1,status=1";
[red]var popWin = [/red]window.open(popURL, 'newWin', options);
[red]popWin.status = "Loading, please wait..."[/red]
}

Changing the message once loaded is best done on the popped page itself.
Do you have any scripts running in it?

ron_ron

3:33 pm on May 7, 2004 (gmt 0)

10+ Year Member



I am afraid that script doesn't work. It opens the wrong page when JS is enabled.

In answer to your question, there are scripts that run the pop-up but those are out of my control. They come from another site.

Bernard Marx

3:38 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am afraid that script doesn't work. It opens the wrong page when JS is enabled.

Which script - both?

...They come from another site.

Then, as you say, they are totally out of your control. Access will be denied.

Bernard Marx

3:53 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry there's definately a quoting error in the onclick.
Should be single quotes:

-- 1 line ---


<a href="http://www.mydomain/page2.htm" onClick="popup('http://www.mydomain/page1.htm',480,500);return false;" target="_blank">

ron_ron

4:10 pm on May 7, 2004 (gmt 0)

10+ Year Member



Perhaps it would be best if you saw the script in action. Please go to:

<snip>

Then click on the button on the left side that says "Instant Quote."

[edited by: korkus2000 at 6:31 pm (utc) on May 7, 2004]
[edit reason] No site reviews please [/edit]

Bernard Marx

4:49 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Seems ok to me ron_ron.

The popup seems ok, and goes to the right URL.

I dunno how to turn off JavaScript in IE (duh), but tried in Netscape with
JS on: all OK
JS off: new page opens with the 'non script' page.

The status bar thing isn't implemented, but it's all OK.
Have I missed something?

ron_ron

5:00 pm on May 7, 2004 (gmt 0)

10+ Year Member



Thanks for taking a look. Yes, Just two minor things I would like to do:

1) Hide the URL you see in the status bar when the pop-up is loading.

2) Have some sort of idicator that the page is loading. As the content of the page actually comes from another site, it is sort of slow loading . At very slow times or with a slow connection, it looks like a blank page.

Bernard Marx

12:17 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I have only just found this message.

You can't affect the new window once it starts to load, as it's outside your domain, but you could temporarily write a page into it which displays your message, then loads the intended URL.


var pageCode = "<p [red]-no line break here-[/red] style='color:blue;'>PageLoading...</p><script>window.location='URL'</script>"
function popup(popURL,popHeight,popWidth)
{
var fullPageCode = pageCode.replace('URL',popURL)
var options="resizable,height="+popHeight+",width="+popWidth
+",scrollbars=1,status=1";
popWin =window.open("", 'newWin', options);
setTimeout("popWin.document.write('"+fullPageCode+"'),500)
}

Have a go at that.

Rambo Tribble

2:56 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A choice, though a bit of a kludge, is to create a popup that's your page which includes an iframe that's the other site's content. That way you still have control of the window while displaying the externally-generated material as its content.

ron_ron

3:15 am on May 8, 2004 (gmt 0)

10+ Year Member



Rambo Tribble,

Thank you for your suggestion but the URL is https and if I use a frame then the padlock won't show. It would mean I would have to have SSL enabled on my server.

Bernard Marx

8:39 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Even kludgier:
Have an invisible iframe that loads the popup page from the start, thus caching the page. This may confuse your referrals record (or whatever it's called) and be contrary to some agreement or other.

ron_ron

5:01 pm on May 9, 2004 (gmt 0)

10+ Year Member



Sorry to take so long getting back. I tried this script and couldn't get it to work. When JS is enable, instead of getting the pop-up, I get the target-"_new" page.

var pageCode = "<p -no line break here-style='color:blue;'>PageLoading...</p><script>window.location='URL'</script>"
function popup(popURL,popHeight,popWidth)
{
var fullPageCode = pageCode.replace('URL',popURL)
var options="resizable,height="+popHeight+",width="+popWidth
+",scrollbars=1,status=1";
popWin =window.open("", 'newWin', options);
setTimeout("popWin.document.write('"+fullPageCode+"'),500)
}

Also, I am not sure what you mean by an "invisible iframe" but any kind of framing I would think would cause the padlock not to display in the browseras the page inside the iframe is SSL. Your script is a good idea if I could get it to work.

Bernard Marx

5:10 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With ref to the last bit...

'Invisible frame' means including an IFRAME element in your main page, but setting it's CSS display property to "none". Set it's src to the URL of the pop-up page. This way it will load when the main page loads.

When the 'button' is clicked, and the pop-up is opened, the page will load from cache. This should have no effect on the padlock.

As to the script not opening a pop-up, I'm not sure. How are you calling it in the HTML (in the event handler)?

ron_ron

5:24 pm on May 9, 2004 (gmt 0)

10+ Year Member



The part about the iframe goes way over my head. As to the html I am using, it is as follows:

<a href="http://www.MySite.com" onClick="popup('https://www.TheOtherSite.com',480,500);return false;" target="newWin">

Bernard Marx

6:48 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should do the trick. The previous one had a couple of stupid quoting errors

var pageCode = "<p style='color:blue;'>Page Loading...</p>"
pageCode+= "<script>window.location='URL'</script>"

function popup(popURL,popHeight,popWidth)
{
var fullPageCode = pageCode.replace('URL',popURL);

var options = "resizable,height="+popHeight+",width="+popWidth
+",scrollbars=1,status=1";

popWin =window.open("", 'newWin', options);

setTimeout("popWin.document.write(\""+fullPageCode+"\")",500);
}

The IFRAME I referred to would simply look like this:


<iframe src = "script_enabled_URL" style="display:none:"></iframe>

Your main page would take longer to load, of course.

ron_ron

4:29 pm on May 10, 2004 (gmt 0)

10+ Year Member



The script works fine. Just one last thing I would like to know. Is there anyway to mask the URL that is shown in the status bar of the pop-up window? I want the status bar so that it shows the locked padlock of the SSL site from which the code is coming from. But I don't want the URL of that site to be obvious.

<a href="http://www.MySite.com" onClick="popup('https://www.TheOtherSite.com',480,500);return false;" target="newWin">

Thanks!

Bernard Marx

9:58 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



NO (It's in another domain - can't do anything)

ron_ron

2:44 pm on May 11, 2004 (gmt 0)

10+ Year Member



OK, I guess that is as far as we can take it. I want to thank you for all your time. I am very pleased with the result. Hope to run into again sometime!