Using MVC 5 Razor Views.
I currently have a link to open a document that sits on the server in my about view as follows........
Basic Training <img src="~/Content/Images/Word.jpg" height="24" width="24" />
What I'd like is to be able to have a link to open this document at a particluar bookmark.
From what I have read so far, it would seem that the bookmark is specified after a # symbol. Unfortunately it doesn't seem to work and the document just opens from the start.
I've tried opening via an action using the #' notation as werll, but as yet, no joy.
FileStream fs = new FileStream(Server.MapPath(#"~\Content\My Doc - Basic Training.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
return File(fs, "My Doc - Basic Training.docx");
I've simply been appending #BoomarkName to the filename. No joy as of yet.
Is it possible?
If so could someone please point me in the right direction.
Just seems to work with #bookmark_name, as explained in How to create a hyperlink from an HTML page to a bookmark in Word.
So:
Basic Training <img src="~/Content/Images/Word.jpg" height="24" width="24" />
Related
is there any way of printing a file on a printer in rails?
Let's assume I have a
def print_url
"/system/tickets/#{print_url_dir}/print.png"
end
and I want to call it with
resource.print_url
I tried already
<%= link_to 'Print', resource.print_url, :onclick => 'window.print();return false;'%>
But that just opened the printer dialog for the site I am on.
Sorry if it is a stupid question or I am missing something.
Thanks and all the best!
If you want to do this from a webpage - it's more of a Javascript task rather than Ruby/Rails one. You can do something like this:
<script type="text/javascript">
var WinPrint = window.open('', '_blank', 'left=0,top=0,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write('<img src="<%= resource.print_url %>" />');
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
</script>
It creates and open new window with content that contains only the image that would like to print, then print the page (which you already noticed that invokes the dialog) and the closes that new window. (I don't think there's a way to skip the dialog opening though).
You can check this answer for more information and examples.
I have basically the same problem as this guy. I have a page, accessed over the web (well, local intranet, if that matters), and it needs to reference images on the client's machine. I know those images are going to be in C:\pics. Internet Explorer lets you just reference them, but I'm having trouble printing properly with internet explorer, so I want to try firefox. The answer on that question says you can create a "resource" with a firefox add-on that pages will be able to reference. However, it doesn't seem to be working. I followed the guide for how to make your first add-on and got the red border to work on mozilla sites. I tried editing that add-on to include a chrome.manifest file that just says this:
resource exposedpics file:///C:/pics
and then the page (an asp page) references exposedpics.
<img align=left border="0" src="resource:///exposedpics/<%=Request("Number")%>.jpg" style="border: 3 solid #<%=bordercolor%>" align="right" WIDTH="110" HEIGHT="110">
the page doesn't show the picture. If I go to View Image Info on the image, I'll see the address is "resource:///exposedpics/8593.jpg" (in my example where I input 8593), but it doesn't show the image here. (yes, the image does exist under c:\pics. if I go to file:///C:/pics/8593.jpg, it loads.)
so maybe I don't know how to use a chrome.manifest. (I'm not sure if I need to reference it somehow in my manifest.json, I'm not.) That stack overflow question also says it's possible to dynamically create resources. so I tried to make my manifest.json say:
{
"manifest_version": 2,
"name": "FirefoxPixExposer",
"version": "1.0",
"description": "allows websites to access C:\\pics",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["expose.js"]
}
]
}
and expose.js says
// Import Services.jsm unless in a scope where it's already been imported
Components.utils.import("resource://gre/modules/Services.jsm");
var resProt = Services.io.getProtocolHandler("resource")
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
var aliasFile = Components.classes["#mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
aliasFile.initWithPath("file:///C:/pics");
var aliasURI = Services.io.newFileURI(aliasFile);
resProt.setSubstitution("ExposedPics", aliasURI);
but the same thing happens, the image doesn't display. I did notice that if I put document.body.style.border = "5px solid red"; at the top of expose.js, I do see a border around the body, but if I move it to below the line Components.utils.import("resource://gre/modules/Services.jsm"); it doesn't show up. Therefore, I suspect the code to dynamically create a resource is broken.
What am I doing wrong? Ultimately, how can I get an image on the client's machine to show up on a page from the internet?
You are writing a WebExtensions so none of the APIs you are trying to use exist.
This includes Components.utils.import, Components.classes etc. You should read Working with files on MDN to get an idea, what is still possible.
I have a link like so
= link_to "https://twitter.com/share", class: "twitter-share-button", data: { url: "https://google.com", text: hack.body, via: "GhettoLifeHack_", hashtags: "ghettolifehack" } do
= image_tag "Tweet", alt: "Social Twitter tweet button"
and no matter how much I change the data-url value, the pre-tweet confirmation page always prepopulates the tweet form field with the url of the referring page, not the one I specified. It also ignores my custom data-text as well.
Why is this happening?
I also have this minified script
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
that I got from here https://about.twitter.com/resources/buttons#tweet
Removing that script doesn't seem to change anything.
edit: upon trying using :'data-url' attributes directly, the output html is the same.
I am testing hardcoded strings and dynamically generated urls at the same time. The first is the dynamic one.
<a class="twitter-share-button" href="https://twitter.com/share" data-via="GhettoLifeHack_" data-url="http://localhost:3000/hacks/1" data-text="asdf comment body" data-hashtags="ghettolifehack">
<img src="/images/Tweet" alt="Tweet" title=""></img>
</a>
The second is the hard coded strings
<a class="twitter-share-button" href="https://twitter.com/share" data-via="GhettoLifeHack_" data-url="httpL//google.com" data-text="custom text" data-hashtags="ghettolifehack">
<img src="/images/Tweet" alt="Tweet" title=""></img>
</a>
I've tested on development and in production. Both have the same behavior of pre-populating the tweet form with the referring url, rather than the specified url and text.
This works in Chrome for me but not in Firefox 32
The code provided by you is perfectly fine and should work as expected.
Many site issues can be caused by corrupt cookies or cache. Try to clear both cookies and the cache. I would suggest you to look into the following link to see why it is not working in firefox
The issue was specific to firefox browser. I'm not sure what addon or setting is causing the conflicts, but it is working perfectly find in chrome, including the popup window.
i am trying to use google translate for localization of an XML file, it has near 350K lines, but some of them contain coding for in-game font size and color, like so:
<replacement><p horizontalalignment="center"><br/><image enablescale="false" imagesetpath="00015590.InterD_Jeryoung_3"/><br/><image enablescale="true" imagesetpath="00015590.Tag_Dungeon_Six_Superior" scalerate="1.5"/><image enablescale="true" imagesetpath="00015590.Tag_Dungeon_Four_Superior" scalerate="1.5"/><br/><image enablescale="true" imagesetpath="00009499.Field_Boss" scalerate="1.4"/>Хмельной лик<br/><br/></p>Уничтожить зараженных насекомых<br/>возле мест обитания их королевы。<br/></replacement>
now for god knows what reason, google translate alters that code in the process of translation into some unacceptable coding, like so:
<replacement> <p horizontalalignment="center"> <br/> <image enablescale="false" imagesetpath="00015590.InterD_Jeryoung_3"/> <br/> <image enablescale = "true "imagesetpath =" 00015590.Tag_Dungeon_Six_Superior "scalerate =" 1.5 "/> <image enablescale="true" imagesetpath="00015590.Tag_Dungeon_Four_Superior" scalerate="1.5"/> <br/> <image enablescale = "true" imagesetpath = "00009499.Field_Boss" scalerate = "1.4" /> Intoxicated face <br/> <br/> </ p> Destroy infected insects <br/> habitats near their queen. <br/> </ replacement>
is there any way to avoid that, why is it happening exactly? anyhelp is appreciated on that matter,thanks
EDIT : i am also looking for a way to input my text and have it out in the same exact language with only the coding mishaps changing, so i can isolate those,build a comparison table and then use that to fix the errors after the actual translation is done, but i don't see a way for selecting the same language as input AND output in google translate, it always forces me choose a different one in input or output, kind of makes sense but if there is a way to do that, i might be able to work around it..
Do not feed Google translate with your Xml file, as far as I know it doesn't understand Xml.
Extract the text from the Xml file.
Feed the text to translate.
Transform the text back to Xml.
You could simply transform the Xml to a text document with a single line per Xml element so it would be easier to turn it back into Xml.
More detail
According to the Toolkit you can upload:
HTML (.HTML)
Microsoft Word (.DOC/.DOCX)
OpenDocument Text (.ODT)
Plain Text (.TXT)
Rich Text (.RTF)
Wikipedia URLs
And a couple of extras such as JSON. So no Xml.
The best way I see is to transform your Xml document into one of these types (I would probably use JSON) and transform it is such a way that it can easily be transformed back again by using either position (1 line in the text file is the first element in the Xml document) or by an id (add the Id or position of the element in the xml hierarchy to the JSON element)
My guess is that the toolkit recognizes the html tags in the xml and escapes them. So another option might be to un-escape the > to > and < to <
Yahoo IM has a neat trick. If you post a URL link to a youtube video, it displays in it's place a flash player with that url's video loaded.
I would like to do the same for my Delphi(7) based chat room (www.magchat.com). The display component is TRichView.
I've scoured Google and sent numerous emails without any success... anyone have any suggestions?
The effect I am trying to achieve is when a User posts a URL link to youtube in the chat program... main form using the TRichView Component... the program would spawn a flash player instead of the url, with the movie playing from the url link. I don't have any idea how to amake this happen, but as I said, I've seen this done in Yahoo's IM program, so it's apparently possible.
There isn't any way to embed twebbrowser in the TRichView Component that I am aware of. I was assuming this would have to be some sort of flash player called when the url is detected. The TRichView Component does support flash.
I hope that's clear. I'm not sure my initial questions was completely clear.
Thanks in advance,
Mark Gundy
www.magchat.com
Whenever you see a http://www.youtube.com/watch URL with a v parameter, just include the following HTML snippet:
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/[video-id]&hl=en&fs=1&">
</param>
<param name="allowFullScreen" value="true">
</param>
<param name="allowscriptaccess" value="always">
</param>
<embed src="http://www.youtube.com/v/[video-id]&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">
</embed>
</object>
replacing each occurrence of [video-id] with the v parameter from the URL.
The above HTML snippet is just the "Embed" code taken straight from the page for a random YouTube video. You can tweak some of the parameters like the size, etc.
TRichView already knows how to display HTML, right? You shouldn't need to embed a TWebBrowser in it. So can't you insert the HTML that Laurence's answer demonstrates? You said the component supports Flash, after all.
If it turns out TRichView doesn't support Flash, then try embedding it as a Delphi control, instead. You already asked how to do that. TRichView says it knows how to insert Delphi controls, so import the Flash ActiveX player into Delphi; that will define a Delphi component, which you should be able to put onto the TRichView.
To be able to embed a youtube video in a Delphi win32 app you need to wrap the flash activeX control into a component, so Watch this video.
To display the video just set the movie property of the TShockWaveFlash component. If your url is http://www.youtube.com/watch?v=oGeCqRfRAcQ - convert this to http://www.youtube.com/v/oGeCqRfRAcQ&hl=en&fs=1
It seems to take awhile for the video to become available, and doesn't seem to work the first time I run the application, no idea why, but I'll let you solve that one (it's the first time I've tried this).
You might also want to look into oEmbed. It's a standard way to request the embedded version of a media file so you don't have to do any of the search/replace recommended by other users. Here's a YouTube example:
You have a YouTube URL:
http://youtube.com/watch?v=M3r2XDceM6A
You make a request to YouTube's oEmbed endpoint to get the embed code:
http://www.youtube.com/we/love/oembed/?url=http%3A//youtube.com/watch%3Fv%3DM3r2XDceM6A&format=json
And they return a JSON response that includes an HTML snippet:
{
"version": "1.0",
"type": "video",
"provider_name": "YouTube",
"provider_url": "http://youtube.com/",
"width": 425,
"height": 355,
"title": "Amazing Nintendo Facts",
"html":
"<object width=\"425\" height=\"355\">
<param name=\"movie\" value=\"http://www.youtube.com/v/M3r2XDceM6A&hl=en\"></param>
<param name=\"wmode\" value=\"transparent\"></param>
<embed src=\"http://www.youtube.com/v/M3r2XDceM6A&hl=en\" type=\"application/x-shockwave-flash\"
wmode=\"transparent\" width=\"425\" height=\"355\"></embed>
</object>",
}
oEmbed is also supported by many other websites: Flickr, Viddler, Qik, Hulu, Vimeo, etc.