Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Niels Pedersen 18 posts 49 karma points
    Jan 25, 2012 @ 12:14
    Niels Pedersen
    0

    Open URL in new window

    Hi

    Great script!

    But is it possible to launch an URL(external) in a new window?`

    Thanks

  • Jon 36 posts 59 karma points
    Jan 25, 2012 @ 12:39
    Jon
    0

    If you are using an anchor (<a>) tag you need to add a 'target' attribute e.g.

    <a href="domain.com/link.html" target="_blank">Link Text</a>
    

    See: http://www.w3schools.com/tags/att_a_target.asp

  • Jason Prothero 422 posts 1243 karma points c-trib
    Jan 25, 2012 @ 18:08
    Jason Prothero
    0

    Yep, Jon is right.  Just open the link in a new window using target=_blank or some other method and it will redirect in the new window to the correct location.

    Thanks,
    Jason 

  • Niels Pedersen 18 posts 49 karma points
    Jan 25, 2012 @ 20:56
    Niels Pedersen
    0

    Thanks for the quick reply, it is very much appreciated.

    The problem is, that the link is in a submenu created based upon the page-structure in the content area. So i don't have much control on the single anchor-tag. The link that needs to be opened in a new window is just one among other internal links in the submenu.

    So when i create a new page in the content area and i choose the PWRedirectPage document type, i only get to choose from the internal pages or external URL. It would be at that point i would be cool to have the option to choose between _blank, _new, _self and so on - or even a cusom target like a iframe.

    Hope it makes sense and sorry for not explaining the problem good enough in the first post :)

  • Jason Prothero 422 posts 1243 karma points c-trib
    Jan 25, 2012 @ 21:41
    Jason Prothero
    0

    You could add a series of true/false checkboxes to the PWRedirectPage DocType and then react accordingly in the Navigation building macro.  Would that work?  I've done that before on other projects.  Like a "isNewWindow" or something.  Then in the Nav code check if isNewWindow is true and add target=_blank to the <a> as an attribute.

    The redirect is a simple user control that can't really control the browser behavior regarding new window, etc.  All the redirection is done server-side.

     

    Thanks,
    Jason 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2012 @ 21:47
    Jeroen Breuer
    0

    Checkbox could work, but perhaps a new dropdown datatype where you can choose your target options might be easier. In razor it would look something like this:

    <a href="domain.com/link.html" target="@Model.target">Link Text</a>

    Jeroen

  • Niels Pedersen 18 posts 49 karma points
    Jan 25, 2012 @ 21:55
    Niels Pedersen
    0

    Thanks guys, i will look into your suggestions and post if something works :)

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 16, 2012 @ 12:01
    Fuji Kusaka
    0

    Hi Guys,

    I have the permanent redirection working as expected but i would rather have the same opened in a new window. I tried to add the target="_blank" but doesnt work. Is there something am missing here? 

    <umbraco:Macro URL="[#urlRedirect]" Is301Redirect="[#isPermanentRedirect]" target="blank" Alias="PWUrlRedirect" runat="server"/>
  • Jason Prothero 422 posts 1243 karma points c-trib
    Jul 16, 2012 @ 19:15
    Jason Prothero
    0

    The trick here is that the Umbraco macro cannot have the target="_blank" on it as that is a very specific tag for Umbraco.  The target="_blank" needs to go on the <a> tag that is referencing the redirect page via the content picker.  For example

    <ahref="domain.com/link.html"target="_blank">Link Text</a>

    Does that make sense?

     

    Thanks,

    Jason

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 16, 2012 @ 19:28
    Fuji Kusaka
    0

    Hi Jason,

    Make sense but here lets say the user click on a link from the homepage itself and if ever he type the url in address bar of his browser he will automatically be redirected to the Url specified.

    It is in fact working as expected but should be able to open in another window. From the example you mentioned earlier i therefore will need to add True/False boolean for that node and if Yes = _blank in the url?

     

  • Jason Prothero 422 posts 1243 karma points c-trib
    Jul 16, 2012 @ 19:35
    Jason Prothero
    0

    Hi Fuji,

    Since the redirect is happening server-side (via ASP.NET) and the popup behavior happens on the front-end in the browser, its actually impossible for the package to popup a window directly.  At least as its currently designed.

    Yes, you could change the DocType to have a true/false and then check that and if it is set to true then add target="_blank" in your markup.  Treat it the same as any other content page.  How would you open a normal content page in a new window conditionally?

     

    Thanks,

    Jason

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 16, 2012 @ 19:55
    Fuji Kusaka
    0

    Yes i got it working....i added a docType True/False and depending on how the admin wants to open the url it will treat it as either as a new window or self.

    In any case if the user type the complete url of the page he will automatically be redirected to the url added, but if however he clicks on the link from the homepage itself then a new window will be open.

    Something like

     <xsl:when test="string(externalUrls)='1'">    
         <a href="{umbraco.library:NiceUrl(@id)}" target="_blank">
    <xsl:value-of select="@nodeName" />  
          </a>
    </xsl:when>

     

    Thanks for your help.

     

    //fuji

  • Jason Prothero 422 posts 1243 karma points c-trib
    Jul 16, 2012 @ 19:59
    Jason Prothero
    0

    Awesome!  Glad you could get it working.  Happy to help.

     

Please Sign in or register to post replies

Write your reply to:

Draft