Home / Internet & Networking / Web design / Java Script Code That Triggers Open In New Window
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2  All - (Bottom) Print
Author Topic: Java Script Code That Triggers Open In New Window  (Read 415 times)
roco
Topic Starter
Rookie



Posts: 21


« on: January 09, 2012, 12:20:04 PM »

Hello all, I am searching for a code that will open,a new URL in a new window when anywhere on my index page is clicked.I have my own website,but want to promote a new website venture,and have come across thousands of codes.Problem is with those codes is that my members have to push a link to access that new URL.I just want them to click anywhere on that index page to "trigger" that new window.I don't want to annoy my customer so will there also be a way to have that new URL "trigger" one time per visit,or per day?I have looked and looked,and have been close but no cigar just yet.You guys have been heaven sent to me in the past,so i thought I would stop be and ask..Thanks Everyone,and I hope everyone is having a great New Year!!

Roco
IP logged
kpac
Web moderator
Moderator
Hacker



Thanked: 180
Posts: 5,874

Certifications: List
Computer: Specs
Experience: Expert
OS: Windows 7
kpac®

1 1 1
« Reply #1 on: January 09, 2012, 12:39:41 PM »

This isn't as easy as you might think, but this should work.

CSS
Code: [Select]
*, html, body {
   width: 100%;
   height: 100%;
}
a.fullscreen {
   display: block;
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   z-index: 9999;
}
First, the HTML document's height and width have to be set to 100%. Then we create the properties for the <a> that will hold the link you want people to click on.

HTML is simple enough...
Code: [Select]
<a href="wherever" class="fullscreen" target="_blank">&nbsp;</a>
This has to be put either at the very top after <body> or at the very end before </body>.

If you want to hide the link when someone clicks on it, javascript will be needed.
« Last Edit: January 09, 2012, 01:21:54 PM by kpac » IP logged

roco
Topic Starter
Rookie



Posts: 21


« Reply #2 on: January 09, 2012, 12:49:02 PM »

Hey kpac!! Hows it going? Thanks for this code sir I will give it a go. And yes I wanted to hide the link,and instead have my members click anywhere on the page to trigger the URL.
IP logged
kpac
Web moderator
Moderator
Hacker



Thanked: 180
Posts: 5,874

Certifications: List
Computer: Specs
Experience: Expert
OS: Windows 7
kpac®

1 1 1
« Reply #3 on: January 09, 2012, 12:57:14 PM »

Sorry, I fixed that in the code above. Just add a &nbsp; to the link instead.
IP logged

roco
Topic Starter
Rookie



Posts: 21


« Reply #4 on: January 09, 2012, 01:19:50 PM »

Ok so where exactly should I place the first code?

*, html, body {
   width: 100%;
   height: 100%;
}
a.fullscreen {
   display: block;
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   z-index: 9999;
}
I just tried to put in the Head section but no luck. Also should I place <a>      *[/url] at the beginning and end of this code? Pretty sure the answer is yes just checking lol.

IP logged
kpac
Web moderator
Moderator
Hacker



Thanked: 180
Posts: 5,874

Certifications: List
Computer: Specs
Experience: Expert
OS: Windows 7
kpac®

1 1 1
« Reply #5 on: January 09, 2012, 01:22:48 PM »

Yeah, the CSS shoulld go in the <head>. The link should go just after the opening <body> tag.
IP logged

lina19
Rookie



Posts: 36

Experience: Beginner
OS: Unknown

« Reply #6 on: January 09, 2012, 02:26:07 PM »

i dont know if u exactly ask this:
try it and see:

<html>


<script type="text/javascript">
function click_on()
{

   
   window.location="a.html";

}
</script>

<body onclick="click_on()">   

</body>
</html>
   
IP logged
kpac
Web moderator
Moderator
Hacker



Thanked: 180
Posts: 5,874

Certifications: List
Computer: Specs
Experience: Expert
OS: Windows 7
kpac®

1 1 1
« Reply #7 on: January 09, 2012, 02:51:11 PM »

Along with a <head>, that would work, and is quite a bit simpler than mine.

Code: [Select]
<html>

<head>
<script type="text/javascript">
function click_on()
{

   
   window.location="a.html";

}
</script>
</head>

<body onclick="click_on()">   

</body>
</html>
IP logged

lina19
Rookie



Posts: 36

Experience: Beginner
OS: Unknown

« Reply #8 on: January 09, 2012, 02:57:50 PM »

hehe....
IP logged
roco
Topic Starter
Rookie



Posts: 21


« Reply #9 on: January 09, 2012, 03:28:38 PM »

Ok which one should I use here  ;D  Kpac when I use yours I can see that actual coding on my index page,so should I start it with <html>?

 And thank you lina19 for your code,but where should I insert my new url,and will this open in a new window?

Thanks to both of you!!
IP logged
kpac
Web moderator
Moderator
Hacker



Thanked: 180
Posts: 5,874

Certifications: List
Computer: Specs
Experience: Expert
OS: Windows 7
kpac®

1 1 1
« Reply #10 on: January 09, 2012, 03:37:15 PM »

Based on Lina's code:

Code: [Select]
<html>

<head>
<script type="text/javascript">
function click_on()
{
   window.open("URL HERE", "_blank");
}
</script>
</head>

<body onclick="click_on()">   

</body>

</html>

Now the link will open in a new window.
IP logged

roco
Topic Starter
Rookie



Posts: 21


« Reply #11 on: January 09, 2012, 03:49:04 PM »

Thank you!! We are definitely on the right path here!! Only two more questions..(You have helped me so much here I feel bad for asking) but when the new URL opens it opens in a new tab,is there a way to have it open in a completely new window? And my second question is there way to only have this window open for new visitors or like once per day per IP address? Currently it is opening in a new tab every time the page is clicked lol. I Hope I am not asking for too much from you two. If I am I understand and very greatfull for what you provided.
IP logged
lina19
Rookie



Posts: 36

Experience: Beginner
OS: Unknown

« Reply #12 on: January 09, 2012, 03:55:20 PM »

its ok...i dont mind...but im not understanding your question clearly...

u mean its opening in another tag??

window.location is supposed to open you to another window....change the filename....try to test it with a fresh page and see...

i havent understood your second ques..

cordialy,
.....
IP logged
lina19
Rookie



Posts: 36

Experience: Beginner
OS: Unknown

« Reply #13 on: January 09, 2012, 04:01:42 PM »

sry...i read it again....i did understand...what u mean...wait i will reply in some minutes
IP logged
roco
Topic Starter
Rookie



Posts: 21


« Reply #14 on: January 09, 2012, 04:07:51 PM »

ok thanks!!
IP logged
Pages: [1] 2  All - (Top) Print 
Home / Internet & Networking / Web design / Java Script Code That Triggers Open In New Window « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.095 seconds with 21 queries.