Link to home
Start Free TrialLog in
Avatar of tjgrindsted
tjgrindsted

asked on

How do i add _Self to a JaveScript Link line.

Hi how do i add target _self to this line of code, right now its work, but it open the link in a new window.

if (con) return true; else window.open('default.aspx');
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

use:
if (con) return true; else window.location('default.aspx');
that refers to the current window.



Cd&

Avatar of tjgrindsted
tjgrindsted

ASKER

Hi

its not working
i have this code
Me.Button2.Attributes.Add("onclick", "var con = confirm('Are you sure you want to update?'); if (con) return true; else window.open('showitems.aspx');")

Open in new window

and its working, if i cancel it open a new window and show the showitems.aspx page (but in a new window)

but if i changes the window.open to window.location and i hit cancel, then it do nothing but updating the record, and thats a fail...
Avatar of Bob Learned
The _self goes in the name argument for the window.open.

open Method
http://msdn.microsoft.com/en-us/library/ms536651(v=vs.85).aspx

sName       Optional. String that specifies the name of the window. This name is used as the value for the TARGET attribute on a form or an anchor element.

_blank
The sURL is loaded into a new, unnamed window.

_media
In Microsoft Internet Explorer 6, the sURL is loaded in the Media Bar.
Windows XP Service Pack 2 (SP2) and later. This feature is no longer supported. By default, the sURL is loaded into a new browser window or tab.

_parent
The sURL is loaded into the current frame's parent. If the frame has no parent, this value acts as the value _self.

_search
Disabled in Windows Internet Explorer 7, see Security and Compatibility in Internet Explorer 7 for details.
Otherwise, the sURL is opened in the browser's search pane in Internet Explorer 5 or later.

_self
The current document is replaced with the specified sURL.

_top
sURL replaces any framesets that may be loaded. If there are no framesets defined, this value acts as the value _self.
OOPs a syntax error on my part.

It should be window.location='default.aspx'



Cd&
Hi TheLearnedOne
I see what U mean, im new to this so hope u can help.
If i understand right then i need to changes it to this
Me.Button2.Attributes.Add("onclick", "var con = confirm('Are you sure you want to update?'); if (con) return true; else window.open('showitems.aspx', '_self');")

Open in new window


BUT it do the same as the use of window.location....so "no go" with that...
Hi COBOL

if i delete the ( ) then the warning is not working at all.
What browser(s) are you using?
Firefox
I will have to dig through my memory cells, to see if I can remember, because I believe that this is something the IE processes differently than FireFox.
Does location.href = 'showitems.aspx' work as expected?
post that line of code as you have now.  there must be an error.


Cd&
@ TheLearnedOne
No its the same error as with window.location and the window.open('showitems.aspx', '_self');


My codebehind is
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'code in page load that should only run when the page loads and not when the page posts back
        If (Not Page.IsPostBack) Then
            ' when trying to update, an alert is showed, about "Are you sure you want to update" if cancel u go to another page.
            Me.Button2.Attributes.Add("onclick", "var con = confirm('Are you sure you want to update?'); if (con) return true; else window.open('showitems.aspx');")
            Try
                openAccessConnection()
                Dim cmd As New OleDbCommand("select * from TBL where the_id =" & updId & "", myAccessConnection)
                ' Mark the Command as a Text
                cmd.CommandType = CommandType.Text
                ' Use ExecuteReader if u dont fill/use a DataSet/DataTable - Repeater/Gridview and want to use response.write
                Dim dbreader As OleDbDataReader = cmd.ExecuteReader
                If dbreader.HasRows Then
                    dbreader.Read()
                    upd_thetitle.Text = dbreader.Item("the_title")
                    upd_thetext.Text = dbreader.Item("the_text")
                    upd_thenumber.Text = dbreader.Item("the_number")
                End If
                dbreader.Close()
            Catch exc As Exception
            Finally
                closeAccessConnection()
            End Try
        End If
    End Sub

Open in new window

i need it to work in IE and FF
What does the code look like on the HTML page, because that is where it has to execute.

Cd&
I don't use FireFox, but it might be a configuration option.

http://answers.yahoo.com/question/index?qid=20080317070947AAVpOMw

That is impossible.
Firefox overrides your code and catches new window event - if tabs are chosen in preferences, it will launch a new tab.

Just go to Tools>Options>Tabs and there is radio buttons there to choose whether you want a new link to open in a new window or a new tab.
ASKER CERTIFIED SOLUTION
Avatar of rajapandian_81
rajapandian_81
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi all

Thx for ur time.....Rajapandian u did it thx.
thx
Welcome ;-)