[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Can a HyperLink bring up a JavaScript window?

Hello,

I have a HyperLink with the following attribute on MyBase.Load:
        Me.HyperLink1.Attributes.Add("onclick", "javascript:new_window('index.aspx', 40, 300)")

The following KavaScript code WORKS.

-------------
JavaScript:

<script language="JavaScript">

     <!--//
          var url="index.aspx";
          function new_window(url,iWidth,iHeight) {

          link = window.open(url,"newWindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=500,left=140,top=50");

          }
     //-->
</script>

-----------
PROBLEM: If I don't set the NavigateUrl property of the Hyperlink in design time and just simply to the attribute, when the page runs the Hyperlink is not a link at all, it's just text. Now, if I set the NavigateUrl property to the same page it will do a roundtrip and I don't want it tobecause there is no need to. On the other hand if I don't set it at all it comes out as plain text.

 I don't want to use a botton.

What should I do?
Thanks in advance




0
avikatz16
Asked:
avikatz16
  • 3
  • 2
1 Solution
 
TimCotteeCommented:
Hi avikatz16,

        Me.HyperLink1.Attributes.Add("onclick", "javascript:new_window('index.aspx', 40, 300);return false;")

Adding return false; should stop it doing the postback if you set the NavigateURL property to the current page or even "#"


Tim Cottee
0
 
avikatz16Author Commented:
thanks
0
 
avikatz16Author Commented:
could you please assist me just a little further?
in the page the opens how can i have it open lets say at a table in the middle of the page?
0
 
TimCotteeCommented:
avikatz16,

Use an internal anchor in the page just above the table:

<a name="OpenHere">
<table> .......

Then your destination URL would be something like "http://mysite.com/folder/popuppage.aspx#OpenHere" 

The #OpenHere is telling the browser to go to the destination anchor on the new page.

Tim
0
 
avikatz16Author Commented:
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now