Jump to content


Can A Div be a link?


10 replies to this topic

#1 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 22 March 2006 - 07:24 AM

I am creating a gallery which when an image(which is a div) is clicked then opens up a new pop up.

i am using the following code in html:

<script TYPE="text/javascript">
<!--
var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=400,width=800');
	if (window.focus) {newwindow.focus()}
}
//-->
</SCRIPT>


and the following where the link should be:

<a href="java script:poptastic('upload.php');">Click Here for Multiple Image Upload</a>


But i cant see how i get the div to fit in with the above code, does anyone have any ideas? thanks

#2 austen

    P2L Jedi

  • Members
  • PipPipPip
  • 910 posts
  • Location:Montana, US
  • Interests:Web design, snowboarding (lots of it), Computer science related.

Posted 22 March 2006 - 09:38 AM

Normally, you would contain the link inside the div... like this:

<div>
<a href="java script:poptastic('upload.php');">Click Here for Multiple Image Upload</a>
</div>

Edited by austen, 22 March 2006 - 04:17 PM.


#3 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 22 March 2006 - 09:47 AM

View Postausten, on Mar 22 2006, 02:38 PM, said:

Normally, you would contain the link inside the div... like this:

[code]
<div>
<a href="java script:poptastic('upload.php');">Click Here for Multiple Image Upload</a>
</div>


Will give that a whirl, thanks

#4 tiki

    Young Padawan

  • Members
  • Pip
  • 259 posts
  • Gender:Male
  • Location:California

Posted 22 March 2006 - 07:00 PM

Can divs use the onclick function?

<div onclick="java script:poptastic('upload.php');">

Im not sure bout you can try.

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 22 March 2006 - 07:26 PM

Divs can both be a link and use the onClick function, catch is, the use of java script:function(); won't work in the onClick tag.

<div onClick="poptastic('upload.php');">

Since it's a JS event handler, we don't need to tell the browser it's JS.

As for the div as a link thing, you can look at my forum for an example. You'd simply put the div in the a tag.

#6 tiki

    Young Padawan

  • Members
  • Pip
  • 259 posts
  • Gender:Male
  • Location:California

Posted 23 March 2006 - 01:56 AM

I was looking at w3schools.com and divs can use all the onclick, onload functions. Its just if your browser supports it.

#7 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 08 May 2006 - 09:14 AM

i have tried to add the javascript line inside the div to be used as a link as this throws all my margins and divs out of place any idea?

thanks

#8 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 08 May 2006 - 03:17 PM

As we've told you before, some code would help us come up with ideas. But my first guess is you mismatched quotes.

#9 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 09 May 2006 - 04:22 AM

Hello thanks for getting back to me

the code i placed is what i was passed from someon else that uses javascript to open a pop up window to specific size.

i want to add code to the indivudal divs on the page to open. using the code below:

<a href="java script:void(0)" onclick="window.open('IMAGE','miniwin',& #39;toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable

=0,width=WIDTH,height=HEIGHT')"


i then added it to the code below:

<div id="content"> 
	<div id="card_1">
	<div id="galleryphoto"><img src="galleryimages/Bruce_Lee_1.jpg" class="img" alt="Bruce Lee 1"></div>
	<div id="galleryphotoname">Bruce Lee 1</div>
	</div>

to give me this:

<div id="content"> 
		  <a href="java script:void(0)" onclick="window.open('www.retrodesigner.co.uk/popups/brucelee1.html','miniwin',& #39;toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable

=0,width=500,height=500')">
	<div id="card_1">
	<div id="galleryphoto"><img src="galleryimages/bruce_Lee_1.jpg" class="img" alt="Bruce Lee 1"></div>
	<div id="galleryphotoname">Bruce Lee 1</div>
	</div></a>

Now i know this code works and seem simple enough to edit, its just the layout issue that i have a problem with.

Any help would be great thanks

Can anyone help me?

#10 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 09 May 2006 - 08:25 PM

2 things.
1. You did mess up the quotes, just not how i thought (you'll probably hit yourself because of how obvious this is).
2. If you're going to use your domain (or any other domain) in a link, regardless of what kind of link it is, don't for get the http:// part.
<a href="java script:void(0);" onclick="window.open('/popups/brucelee1.html', 'miniwin', 'width=500,height=500');">
You should also make sure you use the proper values in open()'s 3 argument, or else some browsers could break on you. And since most attributes default to no, there's no need to put them all in there.

#11 donkeymusic

    Jedi In Training

  • Members
  • PipPip
  • 495 posts
  • Gender:Male
  • Location:Warrington, UK

Posted 10 May 2006 - 03:25 AM

Thanks for that i will look at those changes mentioned

before i read your post i re-added the javascript to my code as an example of what was happening which can be viewed here>>> http://www.retrodesi...uk/gallery2.php when viewed in Internet Explorer all divs are thrown which is what was trying to explain, hopefully your new code will sort that.

thanks

it works, thanks

Edited by donkeymusic, 10 May 2006 - 07:29 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users